﻿using Blog.Core.Domain.Dictionary;
using Blog.Core.DTO;
using Blog.Core.DTO.ViewModel.Dictionary;
using Blog.Core.IServices;
using Blog.Core.IServices.Dictionary;
using Blog.Core.Repositories.Dictionary;
using Blog.Core.Repositories;
using Microsoft.AspNetCore.Authorization;
using Microsoft.AspNetCore.Http;
using Microsoft.AspNetCore.Mvc;

namespace Blog.Core.Api.Controllers.Dictionary
{
    /// <summary>
    /// 字典类型控制器
    /// </summary>
    [Route("api/[controller]/[action]")]
    [ApiController]
    public class DictTypeController : BaseController<DictType>
    {
        private readonly IDictTypeService dictTypeService;

        public DictTypeController(IBaseService<DictType> baseService,IDictTypeService dictTypeService) : base(baseService)
        {
            this.dictTypeService = dictTypeService;
        }
        /// <summary>
        /// 字典类型列表
        /// </summary>
        /// <param name="pageindex"></param>
        /// <param name="pagesize"></param>
        /// <param name="name"></param>
        /// <returns></returns>
        [HttpGet]
        [AllowAnonymous]
        public async Task<IActionResult> GetDictType(int pageindex=1, int pagesize=3, string? name="")
        {
            ResponseResultDTO<int> dto=new ResponseResultDTO<int>();
            if (pageindex < 1  || pagesize<1)
            {
                dto.Message = "参数错误！";
                dto.Code = ResultStatusCode.SUCCESS;
                return Ok(dto);
            }
            return Ok(await dictTypeService.GetDictType(pageindex, pagesize, name));
        }
        /// <summary>
        /// 字典类型录入
        /// </summary>
        /// <param name="dto"></param>
        /// <returns></returns>
        [HttpPost]
        [AllowAnonymous]
        public async Task<IActionResult> PostDictType(PostDictTypeDTO dto)
        {
            return Ok(await dictTypeService.PostDictType(dto));
        }
        /// <summary>
        /// 字典类型修改
        /// </summary>
        /// <param name="dto"></param>
        /// <returns></returns>
        [HttpPut]
        [AllowAnonymous]
        public async Task<IActionResult> PutDictType(PostDictTypeDTO dto)
        {
            return Ok(await dictTypeService.PutDictType(dto));
        }
    }
}
